<template>
    <div style="margin-top: 2%; margin-left: 25%; margin-right: 30%;">
        <el-form ref="form" :model="form" label-width="150px">

            <el-form-item v-for="(value,key) in form" :key="key" :label="labels[key] || key">
                <el-input v-model="form[key]" style="width: 400px"></el-input>
            </el-form-item>
            
           
            <el-form-item>
            <el-button type="primary" @click="onSubmit">添加案例</el-button>
            <el-button type="success" @click="recommend">处方推荐</el-button>
            <el-button>取消</el-button>
            </el-form-item>
        </el-form>
        <!-- <el-empty image="https://shadow.elemecdn.com/app/element/hamburger.9cf7b091-55e9-11e9-a976-7f4d0b07eef6.png"></el-empty> -->

    </div>
</template>


<script>
import axios from 'axios';
import router from '../router';
    export default {
      data() {
        return {
            dialogTableVisible: false,
          form: {
            patient_id: '',
            score1:'',
            score2:'',
            score3:'',
            score4:'',
            qianjinxi_avg:'',
            kuaiji_max:'',
            kuaiji_up:'',
            kuaiji_recover:'',
            manji_avg:'',
            manji_var:'',
            manji_up:'',
            manji_recover:'',
            naili_avg:'',
            naili_var:'',
            naili_rate:'',
            houjingxi_avg:'',
            houjingxi_var:'',
          },
          labels: {
            patient_id: '患者id',
            score1: '问题1',
            score2: '问题2',
            score3: '问题3',
            score4: '问题4',
            qianjinxi_avg: '前静息 平均值',
            kuaiji_max: '快肌 最大值',
            kuaiji_up: '快肌 上升时间',
            kuaiji_recover: '快肌 恢复时间',
            manji_avg: '慢肌 平均值',
            manji_var: '慢肌 变异性',
            manji_up: '慢肌 上升时间',
            manji_recover: '慢肌 恢复时间',
            naili_avg: '耐力 平均值',
            naili_var: '耐力 变异性',
            naili_rate: '耐力 后前10s比值',
            houjingxi_avg: '后静息 平均值',
            houjingxi_var: '后静息 变异性'
      }
        }
      },
      methods: {
        open2() {
        this.$message({
          showClose: true,
          message: '添加成功',
          type: 'success'
        });
      },
      open3() {
        this.$message({
          showClose: true,
          message: '添加失败',
          type: 'error'
        });
      },
        onSubmit() {
          console.log(this.form);
        axios.post('http://localhost:8000/add/patient', this.form)
        .then(response => {
          // 处理成功的响应
        //   alert('添加成功');
          this.open2();
          console.log('添加成功:', response.data);
          console.log(this.form);
          
          // 可以在这里执行其他操作，例如刷新页面或显示成功消息等
        })
        .catch(error => {
          // 处理错误的情况
        //   alert('添加失败');
            this.open3();
          console.error('添加失败:', error);
          console.log(this.form);
        });
        },

        recommend() {
        //   console.log(this.form);
        // axios.post('http://localhost:8000/generate/treatment', this.form)
        // .then(response => {
        //   // 处理成功的响应
        //   alert('生成处方');
        //   console.log('添加成功:', response.data);
        //   console.log(this.form);
          
        //   // 可以在这里执行其他操作，例如刷新页面或显示成功消息等
        // })
        // .catch(error => {
        //   // 处理错误的情况
        //   alert('生成失败');
        //   console.error('添加失败:', error);
        //   console.log(this.form);
        // });
            router.push({ path: '/recommend' });
        }
      }
    }
</script>